/**
 * 
 */
package org.dragonfire.config;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;

/**
 * @author Darth Android
 * @date Aug 19, 2007
 */
public abstract class Config {

	public static final boolean DEFAULT_BOOLEAN = false;

	public abstract String[] getSections(String... path);

	public abstract String[] getKeys(String... path);

	public abstract String getValue(String... path);

	public abstract void putValue(String value, String... path);

	public int getInt(String... path) {
		try {
			return Integer.parseInt(getValue(path));
		} catch (NumberFormatException e) {
			throw new RuntimeException("Key '" + Arrays.toString(path) + "' does not contain a valid integer.");
		}
	}

	public double getDouble(String... path) {
		try {
			return Double.parseDouble(getValue(path));
		} catch (NumberFormatException e) {
			throw new RuntimeException("Key '" + Arrays.toString(path) + "' does not contain a valid double.");
		}
	}

	public boolean getBoolean(String... path) {
		try {
			return Boolean.parseBoolean(getValue(path));
		} catch (NumberFormatException e) {
			return DEFAULT_BOOLEAN; // default
		}
	}

	public abstract void writeFile(OutputStream stream);

	public abstract void importFile(InputStream stream);

	public abstract void importFile(Config conf);
}
